var amapFile = require('../../libs/amap-wx.js');
var util = require('../../libs/util.js');
var amap, mapCtx;
var app = getApp()
Page({
  data: {
    userInfo: {},
    truename: "",
    plate: "",
    driver_id: "",
    middle_height: "100vh"
  },
  onShareAppMessage: function () {
    return {
      title: app.appName,
      path: '/pages/index/index'
    }
  },
  onLoad: function (e) {
    wx.setNavigationBarTitle({ "title": app.appName +"--智冷盒" });
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          middle_height: res.windowHeight - 52,
          client_width: res.windowWidth,
          client_height: res.windowHeight
        });
      }
    });
    that.getLocation();
    var lalt = [];
    // app.socket.on('alliot', function (data) {
    //   if (data.iotbox != app.globalData.iotbox) {
    //     return false;
    //   };

    //   if (data.iotType == "PS") {
    //     lalt.push({
    //       latitude: data.latitude,
    //       longitude: data.longitude
    //     });
    //     that.setData({
    //       lalt: lalt,
    //       polyline: [{
    //         points: lalt,
    //         color: "#0091ff",
    //         width: 3
    //       }]
    //     });
    //   }
    // });
  },
  getLocation(id) {
    var that = this;
    //获取手机定位坐标
    wx.getLocation({
      type: 'gcj02',
      success: function (res) {
        console.log(res.latitude)
        var latitude = res.latitude;
        var longitude = res.longitude;
        that.setData({
          longitude: longitude,
          latitude: latitude
        });

        // lalt.push({
        //   latitude: latitude,
        //   longitude: longitude
        // });

      }
    });
  },
  regionchange: function (res) {
    var that = this;
    mapCtx.getCenterLocation({
      success: function (res) {
        var y = res.longitude;
        var x = res.latitude;
        that.setData({
          locationLongitude: y,
          locationLatitude: x
        })
      }
    })
  },
  gotoScan: function () {
    util.driverScan();
  },
  gotoHome: function () {
    wx.redirectTo({
      url: '/pages/driver/orderList'
    })
  },
  gotoDriverInfo: function () {
    wx.redirectTo({
      url: '/pages/driver/driverInfo'
    })
  },
  gotoCurrentOrder: function () {
    wx.redirectTo({
      url: '/pages/driver/currentOrder'
    })
  },
  gotoIotBox: function () {
    wx.redirectTo({
      url: '/pages/driver/iotBox'
    })
  },
  gotoHistoryOrder: function () {
    wx.redirectTo({
      url: '/pages/driver/historyOrder'
    })
  }
})
